﻿using ET.DBCommon.Enum;
using ET.DBCommon.Model;
using ET_DbCommon.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Input;
namespace RadioStationPOC.Views
{
    /// <summary>
    /// OperationTips.xaml 的交互逻辑
    /// </summary>
    public partial class OperationTips : Window
    {
        public OperationTips(Exam_TestQuestion_Task_StepModel WCurStep, List<TrainClass> TrainList)
        {
            InitializeComponent();
            this.DataContext = OperationTipsList;
        }
        public static OperationTips MyOperationTips = null;
        private static OperationTipsModel OperationTipsList = new OperationTipsModel();
        [DllImport("user32.dll")]
        private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        const int SWP_SHOWWINDOW = 0x0040;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="WCurStep"></param>
        /// <param name="DeviceList"></param>
        /// <returns></returns>
        public static OperationTips Instance(Exam_TestQuestion_Task_StepModel WCurStep, List<TrainClass> TrainList)
        {
            OperationTipsList.OperationtType = ((StepItemEnum)WCurStep.OperateId).ToString();
            OperationTipsList.StepContent = WCurStep.StepContent;
            OperationTipsList.Keyword = WCurStep.KeyWords;
            OperationTipsList.SystemType = WCurStep.SysType;
            OperationTipsList.TrainGroupNumber = WCurStep.DeviceId;
            StringBuilder sb = new StringBuilder();
            foreach (var item in WCurStep.DeviceId.Split(','))
            {
                sb.Append(TrainList.FirstOrDefault(t => t.TrainGroupNumber == item).TrainTimeNumber).Append(",");
            }
            OperationTipsList.TrainTimeNumber = sb.ToString().TrimEnd(',');
            if (MyOperationTips == null)
            {
                MyOperationTips = new OperationTips(WCurStep, TrainList);
            }
            return MyOperationTips;
        }


        #region INotifyPropertyChanged 接口实现
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string propName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
        }
        #endregion
        private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }

        private void DockPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void WindowMin_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void WindowClose_Click(object sender, RoutedEventArgs e)
        {
            if (MyOperationTips != null)
            {
                this.Hide();
            }
            else
            {
                this.Close();
            }
        }

        private void WindowMax_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }
    }
    public class OperationTipsModel : NotifyPropertyChanged
    {

        private string  _systemType;
        /// <summary>
        /// 类型 1/信号2/调度电话3/无线电台
        /// </summary>
        public string  SystemType
        {
            get
            {
                return this._systemType;
            }
            set
            {
                this._systemType = value;
                this.OnPropertyChanged();
            }
        }
        /// <summary>
        /// 操作类型
        /// </summary>
        private string _operationtType;
        public string OperationtType
        {
            get
            {
                return this._operationtType;
            }
            set
            {
                this._operationtType = value;
                this.OnPropertyChanged();
            }
        }

        /// <summary>
        /// 车组号
        /// </summary>
        private string _trainGroupNumber;
        public string TrainGroupNumber
        {
            get
            {
                return this._trainGroupNumber;
            }
            set
            {
                this._trainGroupNumber = value;
                this.OnPropertyChanged();
            }
        }
        /// <summary>
        /// 车次号
        /// </summary>
        private string _trainTimeNumber;
        public string TrainTimeNumber
        {
            get
            {
                return this._trainTimeNumber;
            }
            set
            {
                this._trainTimeNumber = value;
                this.OnPropertyChanged();
            }
        }

        private string _station;
        /// <summary>
        /// 车站
        /// </summary>
        public string Station
        {
            get
            {
                return this._station;
            }
            set
            {
                this._station = value;
                this.OnPropertyChanged();
            }
        }


        private string _stepContent;
        /// <summary>
        /// 播报内容
        /// </summary>
        public string StepContent
        {
            get
            {
                return this._stepContent;
            }
            set
            {
                this._stepContent = value;
                this.OnPropertyChanged();
            }
        }
        private string _keyword;
        /// <summary>
        /// 关键字
        /// </summary>
        public string Keyword
        {
            get
            {
                return this._keyword;
            }
            set
            {
                this._keyword = value;
                this.OnPropertyChanged();
            }
        }
    }
}
